#include "BaseMap.h"



void BaseMapInit()
{
    return ;
}

int PersistenceInMemory(QHash<QString,QString> *map)
{

    return 0;
}


int WatchDogCheckHash(const QString *key,const QString *value)
{
    return key->isEmpty() && value->isEmpty()? -1:1;
}

int WatchDogCheckKey(const QString * key)
{
    return key->isEmpty() ? -1:1;
}

QString GetHashValueByKey(QHash<QString,QString> *map,const QString *key)
{
    if(WatchDogCheckKey(key) == -1) return "";
    QHash<QString,QString>::const_iterator i= map->find(*key);
    while(i!= map->end()){
        return i.value();
    }
    return "";
}

int SetHash(QHash<QString,QString> *map,const QString *key,const QString *value)
{
    if(WatchDogCheckHash(key,value) == -1){
        return INVAILD_KEY_VALUE;
    }
    map->insert(*key,*value);
    return 0;
}

int DelHashByKey(QHash<QString,QString> *map,const QString *key)
{
    if(WatchDogCheckKey(key) == -1){
        return INVAILD_KEY;
    }
    map->remove(*key);
    return 0;
}

int UpdateHashByKey(QHash<QString,QString> *map,const QString *key,const QString *value)
{
    if(WatchDogCheckHash(key,value) == -1){
        return INVAILD_KEY_VALUE;
    }
    map->insert(*key,*value);       //Overwrites the value of an existing item
    return 0;
}

int ShowHashList(QHash<QString,QString> *map,const int size)
{
    QTextStream cout(stdout,QIODevice::ReadWrite);
    int hash_size = size;
    if(map->size() < hash_size) {hash_size = map->size();return INVALID_COMMAND;}
    QHash<QString,QString>::const_iterator it = map->begin();
    int i = 0;
    while(it != map->end() && i < hash_size)
    {
        cout<<i++<<": "<<it.key()<<" <- "<<it.value()<<endl;
        it++;
    }
    return 0;
}







